<template>
    <a href="/show">信息显示</a>
    <h2>信息添加</h2>
    <table class="table">
        <thead>
            <tr>
                <th>用户名</th>
                <th>
                    <input type="text" v-model="data.hname">
                </th>
            </tr>
            <tr>
                <th>密码</th>
                <th>
                    <input type="password" v-model="data.pwd">
                </th>
            </tr>
            <tr>
                <th>房间状态</th>
                <th>
                    <input type="text" v-model="data.zt">
                </th>
            </tr>
            <tr>
                <th>房态编号</th>
                <th>
                    <input type="text" v-model="data.fTbh">
                </th>
            </tr>
            <tr>
                <th></th>
                <th>
                    <input type="button" value="添加" @click="audd">
                </th>
            </tr>
        </thead>
    </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter()
const data=ref({
  "hid": 0,
  "hname": "",
  "pwd": "",
  "zt": 0,
  "fTbh": 0,
  //"deleteID": false
})

const audd=()=>{
    if(data.value.hname=="")
{
    alert('用户名不为空')
    return;
}
if(data.value.pwd=="")
{
    alert('密码不为空')
    return;
}
    axios.post("https://localhost:7095/api/VS/Add",data.value).then(res=>{
        if(res.data>0)
    {
        alert('添加成功')
        router.push({path:"/show"})
    }
    else
    {
        alert('添加失败')
        return
    }
    })
}
</script>

<style scoped>

</style>